﻿from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from time import sleep
from options import options

url = r'http://172.16.22.105:8080/bsams/front/login.do'
driver = webdriver.Chrome(options=options)
driver.get(url)
driver.maximize_window()

# 登录
driver.find_element(By.ID, 'taskId').clear()
driver.find_element(By.ID, 'taskId').send_keys('1')
driver.find_element(By.ID, 'loginName').clear()
driver.find_element(By.ID, 'loginName').send_keys('test03')
driver.find_element(By.ID, 'password').clear()
driver.find_element(By.ID, 'password').send_keys('123456')
driver.find_element(By.ID, 'vericode').clear()
driver.find_element(By.ID, 'vericode').send_keys('shtd')
sleep(3)
driver.find_element(By.XPATH, '//*[@id="fmedit"]/div[2]/div[6]/input').click()
sleep(3)

driver.find_element(By.LINK_TEXT, '资产管理').click()
sleep(2)
driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/div[2]/div[3]/table/tbody/tr[2]/td[8]/a[2]').click()
sleep(1)

# 点击借用部门下拉框
driver.find_element(By.ID, 'departId').click()
sleep(2)
ele = driver.find_element(By.ID, 'departId')
# 选择借用部门
Select(ele).select_by_value('3')
sleep(3)
# 备注说明
driver.find_element(By.ID, 'remark').clear()
driver.find_element(By.ID, 'remark').send_keys('借用一下，马上归还')
# 点击确定
driver.find_element(By.XPATH, '//*[@id="fm_new"]/div/div[1]').click()
sleep(2)

# 弹窗警告
text = driver.switch_to.alert.text
print(text)
sleep(3)
# 点击确定按钮
driver.switch_to.alert.accept()
sleep(3)

# 退出
driver.find_element(By.LINK_TEXT, '退出').click()
sleep(3)

driver.quit()
